/*
 * =====================================================================================
 *
 *       Filename:  aphash.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2014年08月20日 14时26分57秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef __APHASH_H__
#define __APHASH_H__
#include <time.h>
#include "list.h"
#include "common.h"

#ifndef MAX_BUCKET
#define MAX_BUCKET 		(1ul << 14)
#endif
#define IDLE_AP 	(MAX_BUCKET + 1)
#define HASH_OFFSET 	(MAX_BUCKET - 1)

extern struct ap_hash_head_t *aphead;

struct ap_t {
	char 			mac[ETH_ALEN];
	int 			sock;
	uint32_t 		dllrandom;
	uint32_t 		netrandom;
	int 			status;
	char 			reguuid[UUID_LEN];
};

struct ap_hash_t {
	struct hlist_node 	node;
	uint64_t 		mackey;

	/* message list */
	pthread_mutex_t 	msglock; 
	struct list_head 	msghead;
	/* ap stat */
	struct ap_t 		ap;
	time_t 			ts;
};

/* ap hash table */
struct ap_hash_head_t {
	pthread_mutex_t 	lock; 
	struct hlist_head 	head;
};

void aphash_init();
struct ap_hash_t *hash_ap(unsigned char *mac);

#endif /* __APHASH_H__ */
